package lab03.test14;
/*编写JDBC应用程序，首先将用户信息表中的数据在屏幕上显示出来，
然后插入一个记录，最后将更新以后数据表中的数据在屏幕上显示出来。

*/
import java.sql.*;

public class Test14 {

    public static void main(String[] args) {

        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;

        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC",
                    "root",
                    "206227");
            statement = connection.createStatement();
            statement.execute("INSERT INTO  t_userinfo VALUES ('7101','宋晓梅','123456','xiaomei@yahoo.com.cn')");
            statement.execute("INSERT INTO  t_userinfo VALUES ('7102','关松杰','654321','songjie@263.net')");
            statement.execute("INSERT INTO  t_userinfo VALUES ('7103','李晓梅','123654','xiaomei@yahoo.com.cn')");
            statement.execute("INSERT INTO   t_useronfo VALUES ('71004','张岩松',' 456123','songyan@yahoo.com.cn')");
            statement.execute("INSERT INTO  t_userinfo VALUES ('7105','王亚杰','321456','yajie@hotmail.com')");
            statement.execute("INSERT INTO  t_userinfo VALUES ('7106','曲小声','654321','xiaosheng@263.net')");

            resultSet = statement.executeQuery("SELECT * FROM t_userinfo");
            while (resultSet.next()){

                System.out.print(resultSet.getString(1)+"\t");
                System.out.print(resultSet.getString(2)+"\t");
                System.out.print(resultSet.getString(3)+"\t");
                System.out.println(resultSet.getString(4)+"\t");
            }

            statement.execute("INSERT INTO  t_userinfo VALUES ('7107','小明','123546','xiaoming@qq.com')");
            System.out.println("after insert:");
            resultSet = statement.executeQuery("SELECT * FROM t_userinfo");
            while (resultSet.next()) {
                System.out.print(resultSet.getString(1) + "\t");
                System.out.print(resultSet.getString(2) + "\t");
                System.out.print(resultSet.getString(3) + "\t");
                System.out.print(resultSet.getString(4) + "\t");
                System.out.println();
            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}

